//
//  Target_B.m
//  New_Runway
//
//  Created by mack on 2018/1/31.
//  Copyright © 2018年 NelsonJ. All rights reserved.
//

#import "Target_B.h"
#import "NSObject+Target.h"

#import "CarInputVC.h"
#import "HomeWebviewLoadingController.h"
#import "CarFactoyTypeVC.h"
#import "StaffManagerVC.h"
#import "DataCensusVC.h"
#import "CarWinAuctionVC.h"
#import "UndetectedWorkListVC.h"
#import "NRWCarFirstInspectionVC.h"
#import "CrmMainVC.h"
#import "DataWebviewVc.h"
#import "CRMEditorCustomerVC.h"
#import "CrmMailListVC.h"
#import "NRWCarSubscriptionVC.h"
#import "TargetModel.h"
#import "NRWMarketingToolsVC.h"
#import "NRWCarInsuranceManagetVC.h"
//#import "TargetString.h"

@implementation Target_B
- (void)Action_desk:(NSDictionary *)params
{
    NSString *vcType = params[@"params"][@"vc"];
    NSDictionary *jsonDic = [self dictionaryWithJsonString:vcType];
    TargetModel *model = [[TargetModel alloc] init];
    [model setValuesForKeysWithDictionary:jsonDic];
    if ([model.path isEqualToString:kCarInputPath]) {//车辆录入
        CarInputVC *inputVC = [[CarInputVC alloc] init];
        inputVC.isOneKeyPut = NO;
        [[self getTopVC] cyl_pushViewController:inputVC animated:YES];
    }else if ([model.path isEqualToString:kCarFactoryPath]){//在库车辆
        CarFactoyTypeVC *FtypeVC = [[CarFactoyTypeVC alloc] init];
        FtypeVC.type = model.type;
        FtypeVC.userRole = model.role;
        [[self getTopVC] cyl_pushViewController:FtypeVC animated:YES];
    }else if ([model.path isEqualToString:kCrmManagerPath]){//新客户待分配
        CrmMainVC *crmVc = [[CrmMainVC alloc] init];
        if ([model.type isEqualToString:kCrmWillAllotType]) {
            crmVc.infoDic = @{@"followState":@0};
            crmVc.mainTitle = @"新客户待分配";
            crmVc.type = kCRMListViewTypeNewToAssigned;
        }else if ([model.type isEqualToString:kCrmStaffNoDealType]){
            crmVc.infoDic = @{@"followState":@1};
            crmVc.mainTitle = @"员工未处理";
            crmVc.type = kCRMListViewTypeStaffNotProcessed;
        }else if ([model.type isEqualToString:kCrmAllFollowType]){
            crmVc.mainTitle = @"所有客户跟进";
            crmVc.infoDic = @{@"customerShopMode":@"01"};
            crmVc.type = kCRMListViewTypeAllFollowCustomer;
        }else if ([model.type isEqualToString:kCrmAllEndType]){
            crmVc.infoDic = @{@"customerShopMode":@"02"};
            crmVc.mainTitle = @"所有结束客户";
            crmVc.type = kCRMListViewTypeAllEndCustomer;
        }else if ([model.type isEqualToString:kCrmNewAllotWillDealType]){
            crmVc.infoDic = @{@"followState":@1,@"followerId":[NRWCarUser sharedUser].userId};
            crmVc.mainTitle = @"新分配待处理";
            crmVc.type = kCRMListViewTypeNewAssignedPending;
        }else if ([model.type isEqualToString:kCrmTodayDealType]){
            crmVc.infoDic = @{@"customerShopMode":@"04",@"followerId":[NRWCarUser sharedUser].userId};
            crmVc.mainTitle = @"今日待处理";
            crmVc.type = kCRMListViewTypeTodayPending;
        }else if ([model.type isEqualToString:kCrmExpireNoDealType]){
            crmVc.mainTitle = @"过期未处理";
            crmVc.infoDic = @{@"customerShopMode":@"03",@"followerId":[NRWCarUser sharedUser].userId};
            crmVc.type = kCRMListViewTypeExpiredUnprocessed;
        }else if ([model.type isEqualToString:kCrmMyFollowType]){
            crmVc.infoDic = @{@"customerShopMode":@"01",@"followerId":[NRWCarUser sharedUser].userId};
            crmVc.mainTitle = @"我的客户跟进";
            crmVc.type = kCRMListViewTypeMyFollowCustomer;
            
        }else if ([model.type isEqualToString:kCrmMyEndType]){
            crmVc.mainTitle = @"我的结束客户";
            crmVc.infoDic = @{@"customerShopMode":@"02",@"followerId":[NRWCarUser sharedUser].userId};
            crmVc.type = kCRMListViewTypeMyEndCustomer;
        }
        [[self getTopVC] cyl_pushViewController:crmVc animated:YES];
        
    }else if ([model.path isEqualToString:kCrmAddCustomerPath]){//添加客户

        CRMEditorCustomerVC *editXustomerVc = [[CRMEditorCustomerVC alloc] init];
        editXustomerVc.isAddCustomer = YES;

        [[self getTopVC] cyl_pushViewController:editXustomerVc animated:YES];
        
    }else if ([model.path isEqualToString:kCrmContactsPath]){//通讯录
        CrmMailListVC *mailListVc = [[CrmMailListVC alloc] init];
        
        [[self getTopVC] cyl_pushViewController:mailListVc animated:YES];

    }else if ([model.path isEqualToString:kStaffManagerPath]){//员工管理
        StaffManagerVC *staffVC = [[StaffManagerVC alloc] init];
        
        [[self getTopVC] cyl_pushViewController:staffVC animated:YES];
        
    }else if ([model.path isEqualToString:kBrowserPath]){//微店预览

        if ([model.type isEqualToString:kWXShop]) {
            HomeWebviewLoadingController *shopWebVc = [[HomeWebviewLoadingController alloc] init];
            shopWebVc.mainTitle = @"微店预览";
            NSString *shopID;
            if ([NRWCarUser sharedUser].shopId) {
                shopID = [NRWCarUser sharedUser].shopId;
            }else{
                shopID = @"";
            }
            
            shopWebVc.urlstr = [NSString stringWithFormat:@"%@/mshop/src/home.html?shopId=%@&marketId=%@&imgUrl=%@&os=ios",Api,shopID,[NRWCarUser sharedUser].marketId,ImageApi];
            [[self getTopVC] cyl_pushViewController:shopWebVc animated:YES];

        }else if ([model.type isEqualToString:kCarValuation]){
            HomeWebviewLoadingController *shopWebVc = [[HomeWebviewLoadingController alloc] init];
            shopWebVc.mainTitle = @"车辆估值";
            shopWebVc.urlstr =@"http://m.che300.com/pinggu";
            [[self getTopVC] cyl_pushViewController:shopWebVc animated:YES];

        }else if ([model.type isEqualToString:kDataAnalysis]){
            DataWebviewVc *shopWebVc = [[DataWebviewVc alloc] init];
            shopWebVc.urlstr = [NSString stringWithFormat:@"%@/sale/staff/index.html#/show?marketId=%@",Api,[NRWCarUser sharedUser].marketId];
            [[self getTopVC] cyl_pushViewController:shopWebVc animated:YES];
        }else if ([model.type isEqualToString:kRentBuy]){
            HomeWebviewLoadingController *shopWebVc = [[HomeWebviewLoadingController alloc] init];
            shopWebVc.mainTitle = @"以租代购";
            shopWebVc.urlstr = @"https://www.anpxd.com/h5.html?from=groupmessage";
            [[self getTopVC] cyl_pushViewController:shopWebVc animated:YES];
        }else if ([model.type isEqualToString:kInsurance]){
            NRWCarInsuranceManagetVC *InsuranceVC = [[NRWCarInsuranceManagetVC alloc] init];
            NSString *url = [NSString stringWithFormat:@"https://h5.ztwltech.com/zkyq-web/zkyq/begin?agentCode=GLZqjc3oId9Usoyh&accountNo=%@",[NRWCarUser sharedUser].userId];
            InsuranceVC.mainTitle = @"保险管理";
            InsuranceVC.htmlString = url;
            [[self getTopVC] cyl_pushViewController:InsuranceVC animated:YES];
        }
        
    }else if ([model.path isEqualToString:kStatisticsPath]){//数据统计
        DataCensusVC *censusVc = [[DataCensusVC alloc] init];
        [[self getTopVC] cyl_pushViewController:censusVc animated:YES];
        
    }else if ([vcType isEqualToString:@"carDealerLoans"]){//车商贷
        
        
    }else if ([vcType isEqualToString:@"customerLoans"]){//消费贷
        
        
    }else if ([vcType isEqualToString:@"carInsurance"]){//保险
        
        
    }else if ([model.path isEqualToString:kDetectionPath]){//未检测
//        UndetectedWorkListVC *detactedVc = [[UndetectedWorkListVC alloc] init];
//        if ([model.type isEqualToString:kDetectionUndone]) {
//            detactedVc.isdetected = 10;
//        }else if ([model.type isEqualToString:kDetectionDone]){
//            detactedVc.isdetected = 20;
//        }
        NRWCarFirstInspectionVC *vc = [[NRWCarFirstInspectionVC alloc] init];
        [[self getTopVC] cyl_pushViewController:vc animated:YES];
        
    } else if ([model.path isEqualToString:kRetest]) {
        
        UndetectedWorkListVC *detactedVc = [[UndetectedWorkListVC alloc] init];
        [[self getTopVC] cyl_pushViewController:detactedVc animated:YES];
    } else if ([model.path isEqualToString:kCarAutionPath]){ //拍卖
       
        CarWinAuctionVC *auctionVC = [[CarWinAuctionVC alloc] init];
        [[self getTopVC] cyl_pushViewController:auctionVC animated:YES];
        
    }else if ([model.path isEqualToString:kCarSubscribePath]){ //订阅
        
        NRWCarSubscriptionVC *subVC = [[NRWCarSubscriptionVC alloc] init];
        
        [[self getTopVC] cyl_pushViewController:subVC animated:YES];
    }else if ([model.path isEqualToString:kCarSharePath]){
        NRWMarketingToolsVC *shareVc = [[NRWMarketingToolsVC alloc] init];
        [[self getTopVC] cyl_pushViewController:shareVc animated:YES];

    }
    
}
-(NSDictionary *)dictionaryWithJsonString:(NSString *)jsonString {
    if (jsonString == nil) {
        return nil;
    }
    NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
    NSError *error;
    NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&error];
    if(error) {
        NSLog(@"json解析失败：%@",error);
        return nil;
    }
    return dic;
}

@end
